package cn.hrlly.tao2shou.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.hrlly.tao2shou.R;
import cn.hrlly.tao2shou.domain.Requires;

/**
 * User: gengliang
 * Date: 2016-02-13
 * Time: 13:54
 */

public class MyRequiresAdapter extends BaseAdapter {

    private ArrayList<Requires> list;
    private LayoutInflater layoutInflater;

    public MyRequiresAdapter(ArrayList<Requires> list, Context context) {
        this.list = list;
        layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.layout_my_requires, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        Requires require=list.get(position);
        if(require!=null){
            holder.tvRequireTime.setText(require.getRequireTime());
            holder.tvRequireName.setText(require.getRequireTitle());
        }
        return convertView;
    }
    static class ViewHolder {
        @Bind(R.id.tvRequireTime)
        TextView tvRequireTime;
        @Bind(R.id.tvRequireName)
        TextView tvRequireName;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
